#ifndef SPRITE_HEADER
#define SPRITE_HEADER

#include <GL/glfw.h>
#include <glm/glm.hpp>
#include <string>

class SpriteResource{
public:
	SpriteResource () : mHandle(0) {}

	bool Load( const std::string & inFile );

	void SetHandle( unsigned int inHandle) {
		mHandle = inHandle;
	}

	unsigned int GetHandle () {
		return mHandle;
	}

private:
	//Handle to the OpenGL texture
	unsigned int mHandle;
};

class Sprite {

public:
	Sprite  ()
		: mUv(glm::vec2(0,0)) {}
	
	//Sets resource (handle to actual GL data)
	void SetResource( const SpriteResource & inResource ) {
		mResource = inResource;
	}

	//Will draw the sprite
	void Draw() {
		unsigned int handle = mResource.GetHandle();
		if (handle == 0) {
			return;
		}

		glBindTexture(GL_TEXTURE_2D, handle);
		glBegin(GL_QUADS);
		for (int i = 0; i < 4; ++i) {
			glVertex3fv(&(mP[i][0]));
		}

		glEnd();
	}

	void SetPoints( const glm::vec3 & p1, const glm::vec3 & p2,
		const glm::vec3 & p3, const glm::vec3 & p4){
		mP[0] = p1; mP[1] = p2; mP[2] = p3; mP[3] = p4;
	}

	void GetPoints( glm::vec3 inP[4] ) {
		for (int i = 0; i < 4; ++i){
			inP[i] = mP[i];
		}
	}

private:

	SpriteResource mResource;

	glm::vec3 mP[4]; //points
	glm::vec2 mUv;

};

#endif